﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RemotingApp
{
    class Program
    {
        static void Main(string[] args)
        {
            initTasks();
            QuartzManager.startJobs();
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "exit")
                {
                    break;
                }
            }

           QuartzManager.ShutdownJobs();

            Console.WriteLine("服务器已停止！");
            Console.ReadLine();
        }


        private static string xmlPath = System.IO.Path.Combine(System.Environment.CurrentDirectory, "jobs.js");
        private static void initTasks()
        {
            //saveTasks();
            var jsonString = System.IO.File.ReadAllText(xmlPath);
            List<RequestTaskInfo> tasks = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RequestTaskInfo>>(jsonString);
            foreach (var item in tasks)
            {
                if (!item.Enabled)
                {
                    continue;
                }
                Dictionary<string, object> dictionary = new Dictionary<string, object>();
                dictionary.Add("url", item.Url);
                dictionary.Add("parm", item.Parms);
                QuartzManager.addJob<MyJob>(item.JobName, item.CronExpress, dictionary, item.Description);
            }
        }
    }
}
